{% extends "entities/simpleui_change_list_actions.html" %}
{% load i18n admin_urls static admin_list simpletags %}

{% block header %}
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
{% endblock %}

{% block content %}
{{ block.super }}

<script>console.log('============ 这是myLayer!')</script>

<!-- 引入layer.js -->
<script src="https://www.layuicdn.com/layui/layui.js"></script>

<!-- 引入并配置axios -->
<script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>
<script>
    // 拦截request,设置全局请求为ajax请求, 躲过django的csrf验证
    axios.interceptors.request.use((config) => {
        config.headers['X-Requested-With'] = 'XMLHttpRequest';
        let regex = /.*csrftoken=([^;.]*).*$/; // 用于从cookie中匹配 csrftoken值
        config.headers['X-CSRFToken'] = document.cookie.match(regex) === null ? null : document.cookie.match(regex)[1];
        return config
    });
</script>

<script>
    {#content: '/api/myHtml/show.html',   //iframe的url#}
        console.log('~~~~~~ aaaaaaaaa111');

        // 通过审核
        function pass_audit_obj(obj_id) {
            if (1){
                {#data: {#}
                    {#    post_type: 'update',#}
                    {#    order_type_ls:　'-id',#}
                    {#    is_active: '0',#}
                    {#  }#}

                var url = '/api/flow_statistics/Task/' +　obj_id + '/?change_active=1';
                var options = {
                    method: 'get',
                    url: url,
                };

                axios(options)
                    .then(response => {
                            var res = response.data;
                            if (Number(res.status) == 200){
                                console.log('~~~~~~~~~~~~~~~~~~~~~~~ success!');
                                change_is_pass_audit_text(obj_id);
                            }
                            else {
                                console.log('~~~~~~~~~~~~~~~~~~~~~~~ fail!');
                                alert('改变失败! fail!')
                            }
                            console.log('-------- res', res);
                        }
                    )
                    .catch(function (error) { // 请求失败处理
                        console.log('=== axios失败: ', error);
                        alert('改变失败!')
                    });
            }
            // 调用layer弹窗组件
            else {
                layer.open({
                    // 弹窗标题
                    title: "通过审核",
                    // 正文
                    content: "确认通过这篇文章吗？",
                    shadeClose: true,
                    // 点击确定按钮后调用的回调函数
                    yes: function(index, _layer) {

                        // 指定应当前往的 url
                        console.log('~~~ yes', index, _layer);
                        {#$('form#safe_delete button').click();#}
                        layer.close(index);
                    },
                });
            }
        }

        // 编辑
        function change_obj(obj_id) {
            console.log('======= change_obj obj_id', obj_id);

            // 调用layer弹窗组件
            if (0){
                layer.open({
                    // 弹窗标题
                    title: "编辑",
                    // 正文
                    content: "确认编辑这篇文章吗？",
                    // 点击确定按钮后调用的回调函数
                    yes: function(index, _layer) {
                        // 指定应当前往的 url
                        console.log('~~~ yes', index, _layer);
                        {#$('form#safe_delete button').click();#}
                        layer.close(index);
                    },
                });
            }
            if (1){
                var url = '/api/admin/flow_statistics/task/' + obj_id + '/change/'
                {#var url = '/api/template/pdfjs/web/viewer.html?' + file_url;   //iframe的url#}
                    console.log('~~~ url', url);
                    layer.open({
                        id: "son",
                        type: 2,
                        title: '个人信息展示',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['70%', '90%'],
                        content: url,
                    });
                }
            }

            // 预览
            function preview_obj(obj_id) {

                if (1) {
                    // 发送数据, 填写doc模板, 转化为pdf, 然后调用pdfJs预览
                    var url = '/api/flow_statistics/Task/' +　obj_id + '/?fill_doc_template_and_conv_to_pdf=1';
                    var options = {
                        method: 'get',
                        url: url,
                    };

                    axios(options)
                        .then(response => {
                                var res = response.data;
                                if (Number(res.status) == 201){
                                    console.log('~~~~ success! 生成pdf成功, 开始预览pdf');
                                    // change_is_pass_audit_text(obj_id);
                                    var file_url = res.result;
                                    console.log('file_url:', file_url);
                                    var url = '/api/template/pdfjs/web/viewer.html?file=' + file_url;   //iframe的url
                                    console.log('~~~ url', url);
                                    layer.open({
                                        id: "son",
                                        type: 2,
                                        title: '个人信息展示',
                                        shadeClose: true,
                                        shade: 0.8,
                                        area: ['70%', '90%'],
                                        content: url,
                                    });
                                }
                                else {
                                    console.log('~~~~~~~~~~~~~~~~~~~~~~~ fail!');
                                    alert('改变失败! fail!')
                                }
                                console.log('-------- res', res);
                            }
                        )
                        .catch(function (error) { // 请求失败处理
                            console.log('=== axios失败: ', error);
                            alert('改变失败!')
                        });
                } else {
                    console.log('======= obj_id', obj_id);
                    var file_url = '..\\..\\doc\\333.pdf';
                    var url = '/api/template/pdfjs/web/viewer.html?file=' + file_url;   //iframe的url

                    console.log('~~~ url', url);
                    layer.open({
                        id: "son",
                        type: 2,
                        title: '个人信息展示',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['70%', '90%'],
                        content: url,
                    });
                }
            }
</script>

<script>

    function confirm_delete() {
        console.log('~~~~~~~~~~ confirm_delete');
        var data = {
            loading: false,
            name: "用户",
            newUrl: "http://127.0.0.1:8000/api/admin/auth/user/",
            url: "/api/admin/auth/user/"
        };
        var data = {
            loading: true,
            name: "用户1111",
            url: "https://cn.bing.com/?mkt=zh-CN"
        };
        parent.window.app.openTab(data, 0);
    }

    // 使用js实现局部更新
    function change_is_pass_audit_text(id) {
        var elem_3 = document.getElementById('is_pass_audit_' + id);
        {#console.log('--- elem_3: ', elem_3.textContent, elem_3.textContent == '否');#}
        {#elem_3.style="border-style:solid; border-width:1px;";#}

        var elem_active_button = document.getElementById('bdActiveButtonId_' + id);

        if (elem_3.textContent == '否'){
            elem_3.textContent = '是';
            elem_active_button.textContent = '撤销';
        }
        else {
            elem_3.textContent = '否';
            elem_active_button.textContent = '通过';
        }
        {#document.getElementById('is_pass_audit_1').style.display = 'none';#}
    }

</script>

{% endblock %}


